<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
         <father></father>
    </div>
    <template id="father">
        <fieldset>
            <legend>父组件</legend>
            <input type="text" v-model="val">
            <child :value="val" @send="send"></child>
        </fieldset>
    </template>
    <template id="child">
        <fieldset>
            <legend>子组件</legend>
            <button @click="add">增加</button>
            <ul>
                <li v-for="(item,index) of arr" :key="index">
                    {{item}}
                </li>
            </ul>
        </fieldset>
    </template>
    <script src='https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js'></script>
    <script>
        //组件之间的通信
        //父=>子
        //子=>父
        Vue.component("father",{
            template:"#father",
            data(){
                return{
                    val:''
                }
            },
            methods:{
                send(input){
                    console.log(input);
                    this.val="";
                }
            },
            components:{
                "child":{
                    template:"#child",
                    data(){
                        return{
                            arr:["花好月圆","千里共婵娟","喜上眉梢"]
                        }
                    },
                    //可以直接像data里面数据一样展示
                    props:["value"],
                    methods: {
                        add(){
                            this.arr.push(this.value);
                            this.$emit("send",this.value);
                        }
                    }
                }
            }
        })
        const vm = new Vue({
            el:"#app",
            data:{}
        })
    </script>
</body>
</html>